{% extends 'myhome/base.html' %}

    {% block title %}
    <title>BookShop-结算</title>
    {% endblock %}

    {% block con %}
    <!-- breadcrumbs-area-start -->
    <div class="breadcrumbs-area mb-70">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="breadcrumbs-menu">
                        <ul>
                            <li><a href="{% url 'myhome_index' %}">首页</a></li>
                            <li><a href="{% url 'myhome_cartindex' %}">购物车</a></li>
                            <li><a href="#" class="active">订单详情</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- breadcrumbs-area-end -->

    <!-- checkout-area-start -->
    <div class="checkout-area mb-70">
        <div class="container">
            <div class="row">
                <form action="{% url 'myhome_ordercreate'%}" method="POST">
                    {% csrf_token %}
                    <input type="hidden" name="ids" value="{{ request.GET.ids }}">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                        <div class="checkbox-form">
                            <h3>收货信息</h3>
                            <div class="row">
                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 ">
                                    <div class="checkout-form-list">
                                        <label>收件人：<span class="required">*</span></label>
                                        <input type="text" name="name" required>
                                    </div>
                                </div>
                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                    <div class="checkout-form-list">
                                        <label>电话号码： <span class="required">*</span></label>
                                        <input type="text" name="phone" required>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="checkout-form-list">
                                        <label>城市： <span class="required">*</span></label>
                                        <input type="text" name="city" placeholder="省 - 市" required>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="checkout-form-list">
                                        <label>详细地址： <span class="required">*</span></label>
                                        <input type="text" name="address" placeholder="区 - 路/街道" required>
                                    </div>
                                </div>
                            </div>
                            <div class="different-address">
                                <div class="order-notes">
                                    <div class="checkout-form-list">
                                        <label>备注： </label>
                                        <textarea name="remark" placeholder="订单的说明" rows="10" cols="30"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                        <div class="your-order">
                            <h3>结算明细</h3>
                            <div class="your-order-table table-responsive">
                                <table>
                                    <thead>
                                        <tr>
                                            <th class="product-name">商品</th>
                                            <th class="product-total">价格</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% for i in carts %}
                                        <tr class="cart_item">
                                            <td class="product-name">
                                                <img src="{{ i.bid.bookimgs_set.first.img_url }}" alt="" style="width:80px;">
                                                {{ i.bid.title }}<strong class="product-quantity"> × {{ i.num }}</strong>
                                            </td>
                                            <td class="product-total">
                                                {% load calculate %}
                                                <span class="amount">￥<span class="subtotal">{% mul i.num i.bid.price %}</span></span>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                    <tfoot>
                                        <tr class="cart-subtotal">
                                            <th>商品总价：</th>
                                            <td><span class="amount">￥<span class="totals"></span></span></td>
                                        </tr>
                                        <tr class="shipping">
                                            <th>运费：</th>
                                            <td>
                                                <ul>
                                                    <li><span class="amount">￥<span class="freight">10.00</span></span></li>
                                                </ul>
                                            </td>
                                        </tr>
                                        <tr class="order-total">
                                            <th>合计</th>
                                            <td><strong><span class="amount">￥<span class="Totals"></span></span></strong>
                                            </td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                            <div class="payment-method">
                                <div class="order-button-payment">
                                    <input type="submit" value="提交订单">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- checkout-area-end -->
    {% endblock %}

    {% block myjs %}
    <script>
        // 计算价格
        var subtotal = 0
        $('.subtotal').each(function(){
            subtotal += Number($(this).text())
        })
        $('.totals').text(FloatTwo(subtotal))
        T = Number($('.freight').text()) + subtotal
        $('.Totals').text(FloatTwo(T))

        // 保留小数点后两位
        function FloatTwo(value){
            var value = Math.round(parseFloat(value)*100)/100;
            var xsd = value.toString().split('.');
            if(xsd.length == 1){
                value = value.toString() + '.00';
                return value;
            }
            if(xsd.length > 1){
                if(xsd[1].length < 2){
                    value = value.toString() + '0';
                }
                return value;
            }
        }
    </script>

    {% endblock %}





















